package main.string;

import com.google.gson.Gson;
import main.string.utill.JsonUtil;
import org.junit.Test;

import java.util.*;

/**
 * Created by ChengGM on 2016/12/8.
 */
public class StringTest {
	public static Random rand = new Random(32);

	public String toString() {
		StringBuffer sb = new StringBuffer("[");
		for (int i = 0; i < 25; i++) {
			sb.append(rand.nextInt(100));
			sb.append("-->");
		}
		sb.delete(sb.length() - 3, sb.length());
		sb.append("]");
		return sb.toString();
	}

	public static void main(String[] args) {
		StringTest st = new StringTest();
		System.out.println(st);
	}

	@Test
	public void mapTest() {
		Map map = new HashMap();
		map.put("1", 1);
		if (!map.isEmpty()) {

			System.out.println("true");
		}
		System.out.println("false");
	}

	@Test
	public void indexTest() {
		String a = "\\c\\debug\\page.txt";
		int index = a.lastIndexOf("\\");
		String fileName = a.substring(index + 1, a.length());
		System.out.println(fileName + "---- " + index);
		String name = "page.txt";
		System.out.println(name);
	}

	@Test
	public void charTest() {
		char i = '4';
		char j = '9';
		char k = 'A';
		int a = i;
		int b = j;
		int c = k;
		System.out.println(a + " " + b + "  " + c);
	}

	@Test
	public void moveTest() {
		List<String> list = new ArrayList();
		list.add("good");
		list.add("well");
		list.add("not bad");
		list.add("so so");
		Set<String> set = new TreeSet<String>();
		StringBuffer sb = new StringBuffer();
		sb.append("||").append(list.remove(0));
		System.out.println(sb);
		System.out.println(new Gson().toJson(list));
	}

	// 字符串分开存成数组
	@Test
	public void test7() throws Exception {
		String str = "a,b,c,d,e";
		String[] list = str.split(",");
		System.out.println(new Gson().toJson(list));
	}

	@Test
	public void test8() throws Exception {
		String a = "0112";
		String b = "01120024";
		String c = "01120026";
		// boolean f = a - b;
		System.out.println();
	}

	@Test
	public void test9() throws Exception {
		boolean a = true;
		boolean b = false;
		System.out.println(a && b);
		System.out.println(a & b);
	}

	@Test
	public void test10() throws Exception {
		List<Long> idList = new ArrayList<Long>();
		String content = "535#534#532";
		if (null != content) {
			String[] ss = content.split("#");
			List<String> result = Arrays.asList(ss);
			System.out.println(JsonUtil.toJson(result));
			for (String s : result) {
				idList.add(new Long(s.trim()));
			}
		}

		System.out.println(JsonUtil.toJson(idList));
	}

	@Test
	public void test11() throws Exception {
		Long a = 5555L;
		Long b = 5555L;
		System.out.println(a.equals(b));
	}

	@Test
	public void test12() throws Exception {
		String code = "00000003";
		String temp = "00000000000100000001";
		int length = (4 - 3) * 4;
		String tempCode = "";
		for (int i = 0; i < length; i++) {
			tempCode = tempCode + "0";
		}
		System.out.println(tempCode);
		StringBuffer str = new StringBuffer(temp);
		String temp3 = str.substring((code + tempCode).length(), temp.length());
		String temp2 = code + tempCode + temp3;
		System.out.println(temp2);
	}

//	@Test
//	public void test13() throws Exception {
//		String[] str = { "1", "2", "3" };
//		str.Count();
//	}
	

}
